{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "RNN Vs LSTM.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "metadata": {
        "id": "IRQ2F5cKVui4",
        "colab_type": "code",
        "outputId": "5697aa1a-c4f4-498b-95ce-2f497bccbc36",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 122
        }
      },
      "cell_type": "code",
      "source": [
        "# Reading Google drive \n",
        "\n",
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdocs.test%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpeopleapi.readonly&response_type=code\n",
            "\n",
            "Enter your authorization code:\n",
            "··········\n",
            "Mounted at /content/drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "gm76vZ3qXzFy",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# Importing modules\n",
        "\n",
        "# lstm model\n",
        "from numpy import mean\n",
        "from numpy import std\n",
        "from numpy import dstack\n",
        "from pandas import read_csv\n",
        "from keras.models import Sequential\n",
        "from keras.layers import Dense\n",
        "from keras.layers import Flatten\n",
        "from keras.layers import Dropout\n",
        "from keras.layers import SimpleRNN\n",
        "from keras.layers import LSTM\n",
        "from keras.utils import to_categorical\n",
        "from matplotlib import pyplot\n",
        "from keras.models import load_model\n",
        "from keras.utils.vis_utils import model_to_dot\n",
        "from IPython.display import SVG"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "Qp1ROpCpViMw",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# load a single file as a numpy array\n",
        "def load_file(filepath):\n",
        "\tdataframe = read_csv(filepath, header=None, delim_whitespace=True)\n",
        "\treturn dataframe.values"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "1vGb7W4aeaRU",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# load a list of files and return as a 3d numpy array\n",
        "def load_group(filenames, prefix=''):\n",
        "\tloaded = list()\n",
        "\tfor name in filenames:\n",
        "\t\tdata = load_file(prefix + name)\n",
        "\t\tloaded.append(data)\n",
        "\t# stack group so that features are the 3rd dimension\n",
        "\tloaded = dstack(loaded)\n",
        "\treturn loaded"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "fNY21PowekFj",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# load a dataset group, such as train or test\n",
        "def load_dataset_group(group, prefix=''):\n",
        "\tfilepath = prefix + group + '/Inertial Signals/'\n",
        "\t# load all 9 files as a single array\n",
        "\tfilenames = list()\n",
        "\t# total acceleration\n",
        "\tfilenames += ['total_acc_x_'+group+'.txt', 'total_acc_y_'+group+'.txt', 'total_acc_z_'+group+'.txt']\n",
        "\t# body acceleration\n",
        "\tfilenames += ['body_acc_x_'+group+'.txt', 'body_acc_y_'+group+'.txt', 'body_acc_z_'+group+'.txt']\n",
        "\t# body gyroscope\n",
        "\tfilenames += ['body_gyro_x_'+group+'.txt', 'body_gyro_y_'+group+'.txt', 'body_gyro_z_'+group+'.txt']\n",
        "\t# load input data\n",
        "\tX = load_group(filenames, filepath)\n",
        "\t# load class output\n",
        "\ty = load_file(prefix + group + '/y_'+group+'.txt')\n",
        "\treturn X, y"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "TY6YTxc1eqis",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# load the dataset, returns train and test X and y elements\n",
        "def load_dataset(prefix=''):\n",
        "\t# load all train\n",
        "\ttrainX, trainy = load_dataset_group('train', prefix + '/content/drive/My Drive/Colab Notebooks/LAR/data/')\n",
        "\tprint(trainX.shape, trainy.shape)\n",
        "\t# load all test\n",
        "\ttestX, testy = load_dataset_group('test', prefix + '/content/drive/My Drive/Colab Notebooks/LAR/data/')\n",
        "\tprint(testX.shape, testy.shape)\n",
        "\t# zero-offset class values\n",
        "\ttrainy = trainy - 1\n",
        "\ttesty = testy - 1\n",
        "\t# one hot encode y\n",
        "\ttrainy = to_categorical(trainy)\n",
        "\ttesty = to_categorical(testy)\n",
        "\tprint(trainX.shape, trainy.shape, testX.shape, testy.shape)\n",
        "\treturn trainX, trainy, testX, testy"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "dSWk4bh9ujhy",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# fit and evaluate a model\n",
        "def evaluate_RNN_model(trainX, trainy, testX, testy):\n",
        "\tverbose, epochs, batch_size = 0, 15, 64\n",
        "\tn_timesteps, n_features, n_outputs = trainX.shape[1], trainX.shape[2], trainy.shape[1]\n",
        "\tmodel = Sequential()\n",
        "\tmodel.add(SimpleRNN(units=100, input_shape=(trainX.shape[1], \n",
        "    trainX.shape[2])))\n",
        "\tmodel.add(Dropout(0.5))\n",
        "\tmodel.add(Dense(100, activation='relu'))\n",
        "\tmodel.add(Dense(n_outputs, activation='softmax'))\n",
        "\tmodel.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
        "\t# fit network\n",
        "\tmodel.fit(trainX, trainy, epochs=epochs, batch_size=batch_size, verbose=verbose)\n",
        "\t# evaluate model\n",
        "\t_, accuracy = model.evaluate(testX, testy, batch_size=batch_size, verbose=0)\n",
        "\treturn accuracy, model"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "YJsJFx-2erqv",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# fit and evaluate a model\n",
        "def evaluate_LSTM_model(trainX, trainy, testX, testy):\n",
        "\tverbose, epochs, batch_size = 0, 15, 64\n",
        "\tn_timesteps, n_features, n_outputs = trainX.shape[1], trainX.shape[2], trainy.shape[1]\n",
        "\tmodel = Sequential()\n",
        "\tmodel.add(LSTM(100, input_shape=(n_timesteps,n_features)))\n",
        "\tmodel.add(Dropout(0.5))\n",
        "\tmodel.add(Dense(100, activation='relu'))\n",
        "\tmodel.add(Dense(n_outputs, activation='softmax'))\n",
        "\tmodel.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
        "\t# fit network\n",
        "  \n",
        "\tmodel.fit(trainX, trainy, epochs=epochs, batch_size=batch_size, verbose=verbose)\n",
        "  #model.save('/content/drive/My Drive/Colab Notebooks/LAR/LSTM.hdf5')\n",
        "\t# evaluate model\n",
        "\t_, accuracy = model.evaluate(testX, testy, batch_size=batch_size, verbose=0)\n",
        "\treturn accuracy, model"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "YsiOeVGAexAn",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# summarize scores\n",
        "#def summarize_results(scores):\n",
        "\n",
        "#print(scores)\n",
        "#\tm, s = mean(scores), std(scores)\n",
        "#\tprint('Accuracy: %.3f%% (+/-%.3f)' % (m, s))\n",
        "  \n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "fL0uVpXCwOWN",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# run LSTM  experiment\n",
        "def run_RNN_experiment(repeats=10):\n",
        "\t# load data\n",
        "\ttrainX, trainy, testX, testy = load_dataset()\n",
        "\t# repeat experiment\n",
        "\tscores = list()\n",
        "\tfor r in range(repeats):\n",
        "\t\tscore,model = evaluate_RNN_model(trainX, trainy, testX, testy)\n",
        "\t\tscore = score * 100.0\n",
        "\t\tprint('RNN Model Score: >%d: %.3f' % (r+1, score))\n",
        "\t\tscores.append(score)\n",
        "    \n",
        "\treturn model"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "j_HgR1l4fE3m",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# run LSTM  experiment\n",
        "def run_LSTM_experiment(repeats=10):\n",
        "\t# load data\n",
        "\ttrainX, trainy, testX, testy = load_dataset()\n",
        "\t# repeat experiment\n",
        "\tscores = list()\n",
        "\tfor r in range(repeats):\n",
        "\t\tscore,model = evaluate_LSTM_model(trainX, trainy, testX, testy)\n",
        "\t\tscore = score * 100.0\n",
        "\t\tprint('LSTM Model Score: >%d: %.3f' % (r+1, score))\n",
        "\t\tscores.append(score)\n",
        "    \n",
        "\treturn model"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "1ju83i8HfKUP",
        "colab_type": "code",
        "outputId": "edc3a420-e5a1-45f0-864c-64eea65db475",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 238
        }
      },
      "cell_type": "code",
      "source": [
        "RNN_model = run_RNN_experiment()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(7352, 128, 9) (7352, 1)\n",
            "(2947, 128, 9) (2947, 1)\n",
            "(7352, 128, 9) (7352, 6) (2947, 128, 9) (2947, 6)\n",
            "RNN Model Score: >1: 67.933\n",
            "RNN Model Score: >2: 69.766\n",
            "RNN Model Score: >3: 84.153\n",
            "RNN Model Score: >4: 85.137\n",
            "RNN Model Score: >5: 57.448\n",
            "RNN Model Score: >6: 62.776\n",
            "RNN Model Score: >7: 85.103\n",
            "RNN Model Score: >8: 61.486\n",
            "RNN Model Score: >9: 70.139\n",
            "RNN Model Score: >10: 45.945\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "8BJSMRPHpPnm",
        "colab_type": "code",
        "outputId": "8115aa50-ed92-451a-dbd9-1c57d6d45627",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 272
        }
      },
      "cell_type": "code",
      "source": [
        "RNN_model.save('/content/drive/My Drive/Colab Notebooks/LAR/RNN.hdf5')\n",
        "RNN_model.summary()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "simple_rnn_11 (SimpleRNN)    (None, 100)               11000     \n",
            "_________________________________________________________________\n",
            "dropout_14 (Dropout)         (None, 100)               0         \n",
            "_________________________________________________________________\n",
            "dense_27 (Dense)             (None, 100)               10100     \n",
            "_________________________________________________________________\n",
            "dense_28 (Dense)             (None, 6)                 606       \n",
            "=================================================================\n",
            "Total params: 21,706\n",
            "Trainable params: 21,706\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "Q7JToy6iqg1x",
        "colab_type": "code",
        "outputId": "3b0af788-a908-4113-d4ab-e48bc800a03d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 238
        }
      },
      "cell_type": "code",
      "source": [
        "LSTM_model = run_LSTM_experiment()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(7352, 128, 9) (7352, 1)\n",
            "(2947, 128, 9) (2947, 1)\n",
            "(7352, 128, 9) (7352, 6) (2947, 128, 9) (2947, 6)\n",
            "LSTM Model Score: >1: 89.481\n",
            "LSTM Model Score: >2: 87.513\n",
            "LSTM Model Score: >3: 89.956\n",
            "LSTM Model Score: >4: 89.786\n",
            "LSTM Model Score: >5: 89.718\n",
            "LSTM Model Score: >6: 90.804\n",
            "LSTM Model Score: >7: 91.177\n",
            "LSTM Model Score: >8: 88.768\n",
            "LSTM Model Score: >9: 87.920\n",
            "LSTM Model Score: >10: 89.684\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "K9l8bb6T2ym5",
        "colab_type": "code",
        "outputId": "e823cefa-3411-44b8-ec85-a8e18d04b660",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 272
        }
      },
      "cell_type": "code",
      "source": [
        "LSTM_model.save('/content/drive/My Drive/Colab Notebooks/LAR/LSTM.hdf5')\n",
        "LSTM_model.summary()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "lstm_13 (LSTM)               (None, 100)               44000     \n",
            "_________________________________________________________________\n",
            "dropout_24 (Dropout)         (None, 100)               0         \n",
            "_________________________________________________________________\n",
            "dense_47 (Dense)             (None, 100)               10100     \n",
            "_________________________________________________________________\n",
            "dense_48 (Dense)             (None, 6)                 606       \n",
            "=================================================================\n",
            "Total params: 54,706\n",
            "Trainable params: 54,706\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "wM8isBvbejET",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## Model Architecture"
      ]
    },
    {
      "metadata": {
        "id": "PjbMrGZUemuR",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 190
        },
        "outputId": "04d1c862-b064-4558-8eee-09dcaed04ff8"
      },
      "cell_type": "code",
      "source": [
        "rnn = load_model('/content/drive/My Drive/Colab Notebooks/LAR/RNN.hdf5')"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
            "Instructions for updating:\n",
            "Colocations handled automatically by placer.\n",
            "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.\n",
            "Instructions for updating:\n",
            "Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.\n",
            "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
            "Instructions for updating:\n",
            "Use tf.cast instead.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "SuBnYMaXfjqT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 524
        },
        "outputId": "76536408-eaba-4333-b17b-1d0b6dd367c4"
      },
      "cell_type": "code",
      "source": [
        "SVG(model_to_dot(rnn,  show_shapes=True, show_layer_names=True, rankdir='HB').create(prog='dot', format='svg'))"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<IPython.core.display.SVG object>"
            ],
            "image/svg+xml": "<svg height=\"377pt\" viewBox=\"0.00 0.00 350.00 377.00\" width=\"350pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 373)\">\n<title>G</title>\n<polygon fill=\"#ffffff\" points=\"-4,4 -4,-373 346,-373 346,4 -4,4\" stroke=\"transparent\"/>\n<!-- 139700372166248 -->\n<g class=\"node\" id=\"node1\">\n<title>139700372166248</title>\n<polygon fill=\"none\" points=\"0,-249.5 0,-295.5 342,-295.5 342,-249.5 0,-249.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"91\" y=\"-268.8\">simple_rnn_11: SimpleRNN</text>\n<polyline fill=\"none\" points=\"182,-249.5 182,-295.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"211\" y=\"-280.3\">input:</text>\n<polyline fill=\"none\" points=\"182,-272.5 240,-272.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"211\" y=\"-257.3\">output:</text>\n<polyline fill=\"none\" points=\"240,-249.5 240,-295.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"291\" y=\"-280.3\">(None, 128, 9)</text>\n<polyline fill=\"none\" points=\"240,-272.5 342,-272.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"291\" y=\"-257.3\">(None, 100)</text>\n</g>\n<!-- 139700372165464 -->\n<g class=\"node\" id=\"node2\">\n<title>139700372165464</title>\n<polygon fill=\"none\" points=\"28,-166.5 28,-212.5 314,-212.5 314,-166.5 28,-166.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"98.5\" y=\"-185.8\">dropout_14: Dropout</text>\n<polyline fill=\"none\" points=\"169,-166.5 169,-212.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"198\" y=\"-197.3\">input:</text>\n<polyline fill=\"none\" points=\"169,-189.5 227,-189.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"198\" y=\"-174.3\">output:</text>\n<polyline fill=\"none\" points=\"227,-166.5 227,-212.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"270.5\" y=\"-197.3\">(None, 100)</text>\n<polyline fill=\"none\" points=\"227,-189.5 314,-189.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"270.5\" y=\"-174.3\">(None, 100)</text>\n</g>\n<!-- 139700372166248&#45;&gt;139700372165464 -->\n<g class=\"edge\" id=\"edge2\">\n<title>139700372166248-&gt;139700372165464</title>\n<path d=\"M171,-249.3799C171,-241.1745 171,-231.7679 171,-222.8786\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"174.5001,-222.784 171,-212.784 167.5001,-222.784 174.5001,-222.784\" stroke=\"#000000\"/>\n</g>\n<!-- 139700372165296 -->\n<g class=\"node\" id=\"node3\">\n<title>139700372165296</title>\n<polygon fill=\"none\" points=\"41.5,-83.5 41.5,-129.5 300.5,-129.5 300.5,-83.5 41.5,-83.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"98.5\" y=\"-102.8\">dense_27: Dense</text>\n<polyline fill=\"none\" points=\"155.5,-83.5 155.5,-129.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"184.5\" y=\"-114.3\">input:</text>\n<polyline fill=\"none\" points=\"155.5,-106.5 213.5,-106.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"184.5\" y=\"-91.3\">output:</text>\n<polyline fill=\"none\" points=\"213.5,-83.5 213.5,-129.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"257\" y=\"-114.3\">(None, 100)</text>\n<polyline fill=\"none\" points=\"213.5,-106.5 300.5,-106.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"257\" y=\"-91.3\">(None, 100)</text>\n</g>\n<!-- 139700372165464&#45;&gt;139700372165296 -->\n<g class=\"edge\" id=\"edge3\">\n<title>139700372165464-&gt;139700372165296</title>\n<path d=\"M171,-166.3799C171,-158.1745 171,-148.7679 171,-139.8786\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"174.5001,-139.784 171,-129.784 167.5001,-139.784 174.5001,-139.784\" stroke=\"#000000\"/>\n</g>\n<!-- 139699151531816 -->\n<g class=\"node\" id=\"node4\">\n<title>139699151531816</title>\n<polygon fill=\"none\" points=\"41.5,-.5 41.5,-46.5 300.5,-46.5 300.5,-.5 41.5,-.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"98.5\" y=\"-19.8\">dense_28: Dense</text>\n<polyline fill=\"none\" points=\"155.5,-.5 155.5,-46.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"184.5\" y=\"-31.3\">input:</text>\n<polyline fill=\"none\" points=\"155.5,-23.5 213.5,-23.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"184.5\" y=\"-8.3\">output:</text>\n<polyline fill=\"none\" points=\"213.5,-.5 213.5,-46.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"257\" y=\"-31.3\">(None, 100)</text>\n<polyline fill=\"none\" points=\"213.5,-23.5 300.5,-23.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"257\" y=\"-8.3\">(None, 6)</text>\n</g>\n<!-- 139700372165296&#45;&gt;139699151531816 -->\n<g class=\"edge\" id=\"edge4\">\n<title>139700372165296-&gt;139699151531816</title>\n<path d=\"M171,-83.3799C171,-75.1745 171,-65.7679 171,-56.8786\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"174.5001,-56.784 171,-46.784 167.5001,-56.784 174.5001,-56.784\" stroke=\"#000000\"/>\n</g>\n<!-- 139700372166528 -->\n<g class=\"node\" id=\"node5\">\n<title>139700372166528</title>\n<polygon fill=\"none\" points=\"106.5,-332.5 106.5,-368.5 235.5,-368.5 235.5,-332.5 106.5,-332.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"171\" y=\"-346.8\">139700372166528</text>\n</g>\n<!-- 139700372166528&#45;&gt;139700372166248 -->\n<g class=\"edge\" id=\"edge1\">\n<title>139700372166528-&gt;139700372166248</title>\n<path d=\"M171,-332.4092C171,-324.4308 171,-314.795 171,-305.606\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"174.5001,-305.5333 171,-295.5333 167.5001,-305.5334 174.5001,-305.5333\" stroke=\"#000000\"/>\n</g>\n</g>\n</svg>"
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 11
        }
      ]
    },
    {
      "metadata": {
        "id": "24fEq8_jf4YW",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "lstm = load_model('/content/drive/My Drive/Colab Notebooks/LAR/LSTM.hdf5')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "VirO0NRkg-hK",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 524
        },
        "outputId": "a6423c4e-7862-4415-b449-b4c05bcc7aba"
      },
      "cell_type": "code",
      "source": [
        "SVG(model_to_dot(lstm,  show_shapes=True, show_layer_names=True, rankdir='HB').create(prog='dot', format='svg'))"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<IPython.core.display.SVG object>"
            ],
            "image/svg+xml": "<svg height=\"377pt\" viewBox=\"0.00 0.00 294.00 377.00\" width=\"294pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 373)\">\n<title>G</title>\n<polygon fill=\"#ffffff\" points=\"-4,4 -4,-373 290,-373 290,4 -4,4\" stroke=\"transparent\"/>\n<!-- 139698613327968 -->\n<g class=\"node\" id=\"node1\">\n<title>139698613327968</title>\n<polygon fill=\"none\" points=\"8,-249.5 8,-295.5 278,-295.5 278,-249.5 8,-249.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"63\" y=\"-268.8\">lstm_13: LSTM</text>\n<polyline fill=\"none\" points=\"118,-249.5 118,-295.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"147\" y=\"-280.3\">input:</text>\n<polyline fill=\"none\" points=\"118,-272.5 176,-272.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"147\" y=\"-257.3\">output:</text>\n<polyline fill=\"none\" points=\"176,-249.5 176,-295.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"227\" y=\"-280.3\">(None, 128, 9)</text>\n<polyline fill=\"none\" points=\"176,-272.5 278,-272.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"227\" y=\"-257.3\">(None, 100)</text>\n</g>\n<!-- 139700372879232 -->\n<g class=\"node\" id=\"node2\">\n<title>139700372879232</title>\n<polygon fill=\"none\" points=\"0,-166.5 0,-212.5 286,-212.5 286,-166.5 0,-166.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"70.5\" y=\"-185.8\">dropout_24: Dropout</text>\n<polyline fill=\"none\" points=\"141,-166.5 141,-212.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"170\" y=\"-197.3\">input:</text>\n<polyline fill=\"none\" points=\"141,-189.5 199,-189.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"170\" y=\"-174.3\">output:</text>\n<polyline fill=\"none\" points=\"199,-166.5 199,-212.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"242.5\" y=\"-197.3\">(None, 100)</text>\n<polyline fill=\"none\" points=\"199,-189.5 286,-189.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"242.5\" y=\"-174.3\">(None, 100)</text>\n</g>\n<!-- 139698613327968&#45;&gt;139700372879232 -->\n<g class=\"edge\" id=\"edge2\">\n<title>139698613327968-&gt;139700372879232</title>\n<path d=\"M143,-249.3799C143,-241.1745 143,-231.7679 143,-222.8786\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"146.5001,-222.784 143,-212.784 139.5001,-222.784 146.5001,-222.784\" stroke=\"#000000\"/>\n</g>\n<!-- 139698613328752 -->\n<g class=\"node\" id=\"node3\">\n<title>139698613328752</title>\n<polygon fill=\"none\" points=\"13.5,-83.5 13.5,-129.5 272.5,-129.5 272.5,-83.5 13.5,-83.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"70.5\" y=\"-102.8\">dense_47: Dense</text>\n<polyline fill=\"none\" points=\"127.5,-83.5 127.5,-129.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"156.5\" y=\"-114.3\">input:</text>\n<polyline fill=\"none\" points=\"127.5,-106.5 185.5,-106.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"156.5\" y=\"-91.3\">output:</text>\n<polyline fill=\"none\" points=\"185.5,-83.5 185.5,-129.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"229\" y=\"-114.3\">(None, 100)</text>\n<polyline fill=\"none\" points=\"185.5,-106.5 272.5,-106.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"229\" y=\"-91.3\">(None, 100)</text>\n</g>\n<!-- 139700372879232&#45;&gt;139698613328752 -->\n<g class=\"edge\" id=\"edge3\">\n<title>139700372879232-&gt;139698613328752</title>\n<path d=\"M143,-166.3799C143,-158.1745 143,-148.7679 143,-139.8786\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"146.5001,-139.784 143,-129.784 139.5001,-139.784 146.5001,-139.784\" stroke=\"#000000\"/>\n</g>\n<!-- 139698614024176 -->\n<g class=\"node\" id=\"node4\">\n<title>139698614024176</title>\n<polygon fill=\"none\" points=\"13.5,-.5 13.5,-46.5 272.5,-46.5 272.5,-.5 13.5,-.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"70.5\" y=\"-19.8\">dense_48: Dense</text>\n<polyline fill=\"none\" points=\"127.5,-.5 127.5,-46.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"156.5\" y=\"-31.3\">input:</text>\n<polyline fill=\"none\" points=\"127.5,-23.5 185.5,-23.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"156.5\" y=\"-8.3\">output:</text>\n<polyline fill=\"none\" points=\"185.5,-.5 185.5,-46.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"229\" y=\"-31.3\">(None, 100)</text>\n<polyline fill=\"none\" points=\"185.5,-23.5 272.5,-23.5 \" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"229\" y=\"-8.3\">(None, 6)</text>\n</g>\n<!-- 139698613328752&#45;&gt;139698614024176 -->\n<g class=\"edge\" id=\"edge4\">\n<title>139698613328752-&gt;139698614024176</title>\n<path d=\"M143,-83.3799C143,-75.1745 143,-65.7679 143,-56.8786\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"146.5001,-56.784 143,-46.784 139.5001,-56.784 146.5001,-56.784\" stroke=\"#000000\"/>\n</g>\n<!-- 139698613328080 -->\n<g class=\"node\" id=\"node5\">\n<title>139698613328080</title>\n<polygon fill=\"none\" points=\"78.5,-332.5 78.5,-368.5 207.5,-368.5 207.5,-332.5 78.5,-332.5\" stroke=\"#000000\"/>\n<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"143\" y=\"-346.8\">139698613328080</text>\n</g>\n<!-- 139698613328080&#45;&gt;139698613327968 -->\n<g class=\"edge\" id=\"edge1\">\n<title>139698613328080-&gt;139698613327968</title>\n<path d=\"M143,-332.4092C143,-324.4308 143,-314.795 143,-305.606\" fill=\"none\" stroke=\"#000000\"/>\n<polygon fill=\"#000000\" points=\"146.5001,-305.5333 143,-295.5333 139.5001,-305.5334 146.5001,-305.5333\" stroke=\"#000000\"/>\n</g>\n</g>\n</svg>"
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        }
      ]
    },
    {
      "metadata": {
        "id": "TPAVm6FFhFyb",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}